package com.example.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.base.limit.IPRateLimit;
import java.util.List;
import com.example.base.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.example.business.service.SysVideoPlayRecordService;
import com.example.business.entity.SysVideoPlayRecord;
import java.io.Serializable;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiong
 * @since 2024-01-28
 */

@RestController
@Api(tags = {"的服务类"})
@RequestMapping("/sys-video-play-record")
public class SysVideoPlayRecordController {

        @Autowired
        private SysVideoPlayRecordService sysVideoPlayRecordService;


        @PostMapping("/saveorupdate")
        @IPRateLimit(name = "SysVideoPlayRecord-saveorupdate",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的更新和新增接口",notes = "的更新和新增接口")
        public JSONObject save(@RequestBody SysVideoPlayRecord sysVideoPlayRecord) {
                boolean flag= sysVideoPlayRecordService.saveOrUpdate(sysVideoPlayRecord);
                if(flag){
                        return Result.successInfo("保存成功");
                }else {
                        return Result.errorInfo("保存失败");
                }
        }

        @DeleteMapping("/{id}")
        @IPRateLimit(name = "SysVideoPlayRecord-del",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的删除接口",notes = "的删除接口")
        public JSONObject delete(@PathVariable("id") Serializable id) {
                boolean flag = sysVideoPlayRecordService.removeById(id);
                if(flag){
                        return Result.successInfo("删除成功");
                }else {
                        return Result.errorInfo("删除失败");
                }
        }

        @PostMapping("/del/batch")
        @IPRateLimit(name = "SysVideoPlayRecord-delbatch",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的批量删除接口",notes = "的批量删除接口")
        public JSONObject deleteBatch(@RequestBody List<Integer> ids){
                boolean flag =  sysVideoPlayRecordService.removeByIds(ids);
                if(flag){
                        return Result.successInfo("删除成功");
                }else {
                        return Result.errorInfo("删除失败");
                }
        }

        @GetMapping("/getall")
        @IPRateLimit(name = "SysVideoPlayRecord-getall",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的获取全部接口",notes = "的获取全部接口")
        public JSONObject findAll() {
                List<SysVideoPlayRecord> list= sysVideoPlayRecordService.list();
                return Result.successInfo(list);
        }

        @GetMapping("/{id}")
        @IPRateLimit(name = "SysVideoPlayRecord-getid",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的获取一个接口",notes = "的获取一个接口")
        public JSONObject findOne(@PathVariable("id") Serializable id) {
                SysVideoPlayRecord data= sysVideoPlayRecordService.getById(id);
                return Result.successInfo(data);
        }

        @GetMapping("/page")
        @IPRateLimit(name = "SysVideoPlayRecord-page",msg = "系统检测到ip异常访问行为，已暂停访问")
        @ApiOperation(value = "的分页接口",notes = "的分页接口")
        public JSONObject findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize) {
                QueryWrapper<SysVideoPlayRecord> queryWrapper = new QueryWrapper<>();
                IPage<SysVideoPlayRecord> page=sysVideoPlayRecordService.page(new Page<>(pageNum, pageSize),queryWrapper);
                return Result.successInfo(page);
        }
}

